import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        list: [
                 { id: 100, name: "吃饭", isDone: true },
                { id: 101, name: "睡觉", isDone: false },
                { id: 102, name: "打豆豆", isDone: true },
        ],
        isShow:'all'
    },
    mutations: {
        setList(state,taskObj) {
            state.list.unshift(taskObj)
        },
        delList(state, id) {
            state.list.splice(id,1)
        },
        changeIsDone(state) {
            state.list.isDone = !state.list.isDone
        },
        allIsDone(state,isDone) {
            state.list.forEach(item=>item.isDone=isDone)
        },
        changeIsShow(state,isShow) {
            state.isShow = isShow
        },
        clearFinsh(state) {
            state.list = state.list.filter(item=>item.isDone!==true)
        }

    },
    actions:{},
    getters: {
        newIsShowList: state => {
            if (state.isShow === 'yes') {
                return state.list.filter(obj => obj.isDone === true)
            } else if (state.isShow === 'no') {
                return state.list.filter(obj => obj.isDone === false)
            } else {
                return state.list
            }
        }
    }
})